#include "Print.h"
#include <iomanip>

const string symbolStrings[] = 
{
    "<no token>", "<IDENTIFIER>", "<NUMBER>", "<STRING>",
    "^","*","(",")","-","+","=","[","]",":",";",
    "<",">",",",".","/",":=","<=",">=","<>","..",
    "<END OF FILE>", "<ERROR>",
    "AND","ARRAY","BEGIN","CASE","CONST","DIV","DO","DOWNTO",
    "ELSE","END","FILE","FOR","FUNCTION","GOTO","IF","IN",
    "LABEL","MOD","NIL","NOT","OF","OR","PACKED","PROCEDURE",
    "PROGRAM","RECORD","REPEAT","SET","THEN","TO","TYPE","UNTIL",
    "VAR","WHILE","WITH",
};

Print::Print(const string &filename)
{
	// save the filename to our private class variable 'fName'
	fName = filename;

	// create a new clock instance
	time_t clock = time(NULL);

	// save the date string to the private class variable 'date'
	date = ctime(&clock);

	// initialize the line count and page number to zero
	lineCount = 0;
	pageNumber = 0;
}

Print::~Print()
{
	// this does not need to be used. Called when the class is being destroyed.
}

void Print::PrintLine(const string &line)
{
	// Increase line count
	lineCount++;
        
	// if this is the first page, or the amount of lines on the page exceeds the max, call PrintPageHeader();
	if(pageNumber == 0 || lineCount / pageNumber > MAX_LINES_PER_PAGE)
	{
		PrintPageHeader();
	}

	// create the formatted line
	cout << right << std::setw(3) << lineCount << ": " << line.c_str();

}

void Print::PrintPageHeader()
{
	// increase the page number
	pageNumber++;

	// print the page header
	printf("Page %3i  %s  %s", pageNumber, fName.c_str(), date.c_str());
}

void Print::PrintToken(Tokenizer &tokenizer)
{
	// this needs to be worked on
	cout <<  "    >> " << left << std::setw(17) << symbolStrings[tokenizer.GetTokenCode()].c_str()<< tokenizer.GetTokenString().c_str() << endl;
	
}
